#include <iostream>
#include <string>

using namespace std;

int GetAnswer(string& strTarget, string& strSource)
{
	for (string::const_iterator iterTarget=strTarget.begin(); iterTarget!=strTarget.end(); iterTarget++)
	{
		int icount = 0;
		for (string::const_iterator iterSource=strSource.begin(); iterSource!=strSource.end(); iterSource++)
		{
			if (*iterTarget == *iterSource)
			{
				icount++;
			}			
		}
		cout<<*iterTarget<<" "<<icount<<endl;
	}
	strTarget.clear();
	strSource.clear();
	return 1;
}
int main()
{
	string strTarget;
	string strSource;
	char tTemp;
	while (cin.get(tTemp))
	{
		if (tTemp == '#')
		{
			return 0;
		}

		if (tTemp == '\n')
		{
			char sTemp;
			while(cin.get(sTemp))
			{
				if (sTemp == '\n')
				{
					break;
				}
				strSource.push_back(sTemp);
			}
			GetAnswer(strTarget,strSource);	
			continue;
		}
		strTarget.push_back(tTemp);
		
	}
	
	//system("pause");
	return 1;
}
